package com.blueocean_health.care.management.transfer.client;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestMapping;

import com.alibaba.fastjson.JSON;
import com.blueocean_health.care.management.domain.base.SysResult;
import com.blueocean_health.care.management.transfer.client.NurseGroupService.HystrixClientFallback;

/**
 * 
 *
 *
 * @Title: NurseGroupClient.java
 * @Package com.blueocean_health.care.management.transfer.client
 * @author luxue
 * @date 2018年7月5日
 * @version V1.0
 */
@FeignClient(value = "workerserver",fallback = HystrixClientFallback.class)
public interface NurseGroupService {
	/**
	 * 小组下拉列表 2018年5月16日17:57:49
	 * 
	 * @return
	 */
	@RequestMapping("nurse/group/pull")
	public SysResult pull(String jsonStr);

	/**
	 * 查询小组
	 * 
	 * @return
	 */
	@RequestMapping("nurse/group/query")
	public SysResult query(String jsonStr);

	/**
	 * 小组列表
	 * 
	 * @return
	 */
	@RequestMapping("nurse/group/list")
	public SysResult list(String jsonStr);

	/**
	 * 导出Excel
	 * 
	 * @return
	 */
	// @RequestMapping("nurse/group/list-excel")
	// public void exportListExcel(SelectNurseGroupDto selectNurseGroupDto, User
	// currentUserInfo);
	@RequestMapping("nurse/group/listExcel")
	public SysResult listExcel(String jsonStr);

	/**
	 * 选择成员
	 * 
	 * @return
	 */
	@RequestMapping("nurse/group/nurse/select-nurse")
	public SysResult selectNurse(String jsonStr);

	/**
	 * 模糊查询小组
	 * 
	 * @return
	 */
	@RequestMapping("nurse/group/select-group")
	public SysResult selectGroup(String jsonStr);

	// @RequestMapping("nurse/group/add")
	// public SysResult insertNurseGroup(String jsonStr) throws OrderException;
	//
	// @RequestMapping("nurse/group/delete")
	// public SysResult deleteNurseGroup(String jsonString) throws OrderException;

	@Component
	static class HystrixClientFallback implements NurseGroupService {
		private static Logger logger = LoggerFactory.getLogger(HystrixClientFallback.class);

		private SysResult getResult(Object object) {

			if (object instanceof String) {
				logger.info("异常发生，进入fallback方法，接收的参数：" + String.valueOf(object));
				return SysResult.error(String.valueOf(object));
			} else {
				logger.info("异常发生，进入fallback方法，接收的参数：" + JSON.toJSONString(object));
				return SysResult.error(JSON.toJSONString(object));
			}
		}

		/* (non-Javadoc)
		 * @see com.blueocean_health.care.management.transfer.client.NurseGroupService#pull(com.blueocean_health.care.management.domain.base.User)
		 */
		@Override
		public SysResult pull(String jsonStr) {
			return getResult(jsonStr);
		}

		/* (non-Javadoc)
		 * @see com.blueocean_health.care.management.transfer.client.NurseGroupService#query(java.lang.String)
		 */
		@Override
		public SysResult query(String jsonStr) {
			return getResult(jsonStr);
		}

		/* (non-Javadoc)
		 * @see com.blueocean_health.care.management.transfer.client.NurseGroupService#list(java.lang.String)
		 */
		@Override
		public SysResult list(String jsonStr) {
			return getResult(jsonStr);
		}

		/* (non-Javadoc)
		 * @see com.blueocean_health.care.management.transfer.client.NurseGroupService#listExcel(java.lang.String)
		 */
		@Override
		public SysResult listExcel(String jsonStr) {
			return getResult(jsonStr);
		}

		/* (non-Javadoc)
		 * @see com.blueocean_health.care.management.transfer.client.NurseGroupService#selectNurse(java.lang.String)
		 */
		@Override
		public SysResult selectNurse(String jsonStr) {
			return getResult(jsonStr);
		}

		/* (non-Javadoc)
		 * @see com.blueocean_health.care.management.transfer.client.NurseGroupService#selectGroup(java.lang.String)
		 */
		@Override
		public SysResult selectGroup(String jsonStr) {
			return getResult(jsonStr);
		}
	}
}
